from flask import Flask, request, redirect, session
import jwt
import uuid

app = Flask(__name__)
app.secret_key = 'your_sso_secret_key'
SECRET_KEY = 'your_sso_jwt_secret_key'

@app.route('/authorize')
def login():
    if 'user' in session:
        # 用户已登录，生成新的令牌
        token = jwt.encode({'user': session['user']}, SECRET_KEY, algorithm='HS256')
        redirect_uri = request.args.get('redirect_uri')
        return redirect(f'{redirect_uri}?token={token}')
    

    # 这里可以实现登录页面等逻辑
    return 'Please login'

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=False, port=5000)